# Prometheus环境变量配置文件
# 此文件定义Prometheus服务运行时的环境变量
# 这些变量将被systemd服务文件引用

# === 基本配置 ===
# Prometheus额外启动参数
PROMETHEUS_OPTS="{% for opt in prometheus_environment_opts %}{{ opt }} {% endfor %}"

# === 性能调优 ===
# Go运行时配置
{% if prometheus_gomaxprocs is defined %}
GOMAXPROCS={{ prometheus_gomaxprocs }}
{% else %}
# 自动检测CPU核心数
GOMAXPROCS={{ ansible_processor_vcpus | default(ansible_processor_cores) }}
{% endif %}

# Go垃圾回收配置
{% if prometheus_gogc is defined %}
GOGC={{ prometheus_gogc }}
{% endif %}

# Go内存限制
{% if prometheus_gomemlimit is defined %}
GOMEMLIMIT={{ prometheus_gomemlimit }}
{% endif %}

# === 调试配置 ===
{% if prometheus_debug_enabled %}
# 启用调试模式
PROMETHEUS_DEBUG=true

# 调试级别
{% if prometheus_debug_level is defined %}
PROMETHEUS_DEBUG_LEVEL={{ prometheus_debug_level }}
{% endif %}

# 性能分析
{% if prometheus_pprof_enabled %}
PROMETHEUS_PPROF=true
{% endif %}
{% endif %}

# === 日志配置 ===
{% if prometheus_log_level is defined %}
PROMETHEUS_LOG_LEVEL={{ prometheus_log_level }}
{% endif %}

{% if prometheus_log_format is defined %}
PROMETHEUS_LOG_FORMAT={{ prometheus_log_format }}
{% endif %}

# === 网络配置 ===
# 监听地址
{% if prometheus_web_listen_address is defined %}
PROMETHEUS_WEB_LISTEN_ADDRESS={{ prometheus_web_listen_address }}
{% endif %}

# 外部URL
{% if prometheus_web_external_url is defined %}
PROMETHEUS_WEB_EXTERNAL_URL={{ prometheus_web_external_url }}
{% endif %}

# === 存储配置 ===
# 数据保留时间
{% if prometheus_retention_time is defined %}
PROMETHEUS_RETENTION_TIME={{ prometheus_retention_time }}
{% endif %}

# 数据保留大小
{% if prometheus_retention_size is defined %}
PROMETHEUS_RETENTION_SIZE={{ prometheus_retention_size }}
{% endif %}

# === 查询配置 ===
# 最大并发查询数
{% if prometheus_query_max_concurrency is defined %}
PROMETHEUS_QUERY_MAX_CONCURRENCY={{ prometheus_query_max_concurrency }}
{% endif %}

# 查询超时时间
{% if prometheus_query_timeout is defined %}
PROMETHEUS_QUERY_TIMEOUT={{ prometheus_query_timeout }}
{% endif %}

# 最大样本数
{% if prometheus_query_max_samples is defined %}
PROMETHEUS_QUERY_MAX_SAMPLES={{ prometheus_query_max_samples }}
{% endif %}

# === 告警配置 ===
# Alertmanager通知队列容量
{% if prometheus_alertmanager_notification_queue_capacity is defined %}
PROMETHEUS_ALERTMANAGER_NOTIFICATION_QUEUE_CAPACITY={{ prometheus_alertmanager_notification_queue_capacity }}
{% endif %}

# Alertmanager超时时间
{% if prometheus_alertmanager_timeout is defined %}
PROMETHEUS_ALERTMANAGER_TIMEOUT={{ prometheus_alertmanager_timeout }}
{% endif %}

# === 安全配置 ===
{% if prometheus_web_config_file is defined %}
PROMETHEUS_WEB_CONFIG_FILE={{ prometheus_web_config_file }}
{% endif %}

# === 功能开关 ===
{% if prometheus_web_enable_lifecycle %}
PROMETHEUS_WEB_ENABLE_LIFECYCLE=true
{% endif %}

{% if prometheus_web_enable_admin_api %}
PROMETHEUS_WEB_ENABLE_ADMIN_API=true
{% endif %}

# === 自定义环境变量 ===
{% if prometheus_custom_environment_vars is defined %}
{% for key, value in prometheus_custom_environment_vars.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}

# === Java应用监控配置（如果需要） ===
{% if prometheus_java_opts is defined %}
JAVA_OPTS="{{ prometheus_java_opts }}"
{% endif %}

# === 时区配置 ===
{% if prometheus_timezone is defined %}
TZ={{ prometheus_timezone }}
{% else %}
TZ={{ ansible_date_time.tz }}
{% endif %}

# === 语言环境 ===
{% if prometheus_locale is defined %}
LANG={{ prometheus_locale }}
LC_ALL={{ prometheus_locale }}
{% endif %}

# === 临时目录 ===
{% if prometheus_tmp_dir is defined %}
TMPDIR={{ prometheus_tmp_dir }}
{% endif %}

# === 进程限制 ===
{% if prometheus_ulimit_nofile is defined %}
PROMETHEUS_ULIMIT_NOFILE={{ prometheus_ulimit_nofile }}
{% endif %}

{% if prometheus_ulimit_nproc is defined %}
PROMETHEUS_ULIMIT_NPROC={{ prometheus_ulimit_nproc }}
{% endif %}